package com.qianya.oa.config.activiti;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.activiti.bpmn.model.BaseElement;
import org.activiti.bpmn.model.CustomProperty;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.UserTask;
import org.activiti.editor.language.json.converter.UserTaskJsonConverter;

import java.util.Map;

/**
 * 节点自定义扩展字段
 */
public class CustomUserTaskJsonConverter extends UserTaskJsonConverter {

    @Override
    protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
        FlowElement flowElement = super.convertJsonToElement(elementNode,modelNode,shapeMap);
        UserTask userTask = (UserTask)flowElement;
        CustomProperty customProperty = new CustomProperty();
 		//添加扩展属性的名称对应stencilset.json里定义的id
 		customProperty.setName("readonly");
        customProperty.setSimpleValue(String.valueOf(getPropertyValueAsBoolean("readonly",elementNode)));
        userTask.getCustomProperties().add(customProperty);
        return userTask;
    }

    @Override
   protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
        super.convertElementToJson(propertiesNode,baseElement);
    }
}

